package org.heart.config;

import org.heart.config.interceptor.Interceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

import javax.annotation.Resource;


@Configuration
public class WebConfig implements WebMvcConfigurer {

    private static final Logger log = LoggerFactory.getLogger(WebConfig.class);

    @Value("${file.path}")
    public String filePath;

    @Resource
    private Interceptor interceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        /**
         * 访问的URL路径
         */
        registry.addResourceHandler("/upload/**")
                /**
                 * 静态资源文件的存储位置
                 */
                .addResourceLocations("file:" + filePath);
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("注册拦自定义截器配置！");
        registry.addInterceptor(interceptor)
                .addPathPatterns("/**") // 拦截所有路径
                .excludePathPatterns("/api/test",
                        "/api/**",
                        "/**",
                        "/wx/**"); // 放行特定路径
    }

}
